
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>email.iterators: 迭代器 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="json --- JSON 编码和解码器" href="json.html" />
    <link rel="prev" title="email.utils: 其他工具" href="email.utils.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/email.iterators.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="json.html" title="json --- JSON 编码和解码器"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="email.utils.html" title="email.utils: 其他工具"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="netdata.html" >互联网数据处理</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="email.html" accesskey="U"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code> --- 电子邮件与 MIME 处理包</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-email.iterators">
<span id="email-iterators-iterators"></span><h1><a class="reference internal" href="#module-email.iterators" title="email.iterators: Iterate over a  message object tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.iterators</span></code></a>: 迭代器<a class="headerlink" href="#module-email.iterators" title="永久链接至标题">¶</a></h1>
<p><strong>源代码:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/email/iterators.py">Lib/email/iterators.py</a></p>
<hr class="docutils" />
<p>通过 <a class="reference internal" href="email.compat32-message.html#email.message.Message.walk" title="email.message.Message.walk"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.walk</span></code></a> 方法来迭代消息对象树是相当容易的。 <a class="reference internal" href="#module-email.iterators" title="email.iterators: Iterate over a  message object tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.iterators</span></code></a> 模块提供了一些适用于消息对象树的高层级迭代器。</p>
<dl class="function">
<dt id="email.iterators.body_line_iterator">
<code class="sig-prename descclassname">email.iterators.</code><code class="sig-name descname">body_line_iterator</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">decode=False</em><span class="sig-paren">)</span><a class="headerlink" href="#email.iterators.body_line_iterator" title="永久链接至目标">¶</a></dt>
<dd><p>此对象会迭代 <em>msg</em> 的所有子部分中的所有载荷，逐行返回字符串载荷。 它会跳过所有子部分的标头，并且它也会跳过任何包含不为 Python 字符串的载荷的子部分。 这基本上等价于使用 <a class="reference internal" href="io.html#io.TextIOBase.readline" title="io.TextIOBase.readline"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readline()</span></code></a> 从一个文件读取消息的纯文本表示形式，并跳过所有中间的标头。</p>
<p>可选的 <em>decode</em> 会被传递给 <a class="reference internal" href="email.compat32-message.html#email.message.Message.get_payload" title="email.message.Message.get_payload"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.get_payload</span></code></a>。</p>
</dd></dl>

<dl class="function">
<dt id="email.iterators.typed_subpart_iterator">
<code class="sig-prename descclassname">email.iterators.</code><code class="sig-name descname">typed_subpart_iterator</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">maintype='text'</em>, <em class="sig-param">subtype=None</em><span class="sig-paren">)</span><a class="headerlink" href="#email.iterators.typed_subpart_iterator" title="永久链接至目标">¶</a></dt>
<dd><p>此函数会迭代 <em>msg</em> 的所有子部分，只返回其中与 <em>maintype</em> 和 <em>subtype</em> 所指定的 MIME 类型相匹配的子部分。</p>
<p>请注意 <em>subtype</em> 是可选项；如果省略，则仅使用主类型来进行子部分 MIME 类型的匹配。 <em>maintype</em> 也是可选项；它的默认值为 <em class="mimetype">text</em>。</p>
<p>因此，在默认情况下 <a class="reference internal" href="#email.iterators.typed_subpart_iterator" title="email.iterators.typed_subpart_iterator"><code class="xref py py-func docutils literal notranslate"><span class="pre">typed_subpart_iterator()</span></code></a> 会返回每一个 MIME 类型为 <em class="mimetype">text/*</em> 的子部分。</p>
</dd></dl>

<p>增加了以下函数作为有用的调试工具。 它 <em>不应当</em> 被视为该包所支持的公共接口的组成部分。</p>
<dl class="function">
<dt id="email.iterators._structure">
<code class="sig-prename descclassname">email.iterators.</code><code class="sig-name descname">_structure</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">fp=None</em>, <em class="sig-param">level=0</em>, <em class="sig-param">include_default=False</em><span class="sig-paren">)</span><a class="headerlink" href="#email.iterators._structure" title="永久链接至目标">¶</a></dt>
<dd><p>打印消息对象结构的内容类型的缩进表示形式。 例如:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">msg</span> <span class="o">=</span> <span class="n">email</span><span class="o">.</span><span class="n">message_from_file</span><span class="p">(</span><span class="n">somefile</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_structure</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="go">multipart/mixed</span>
<span class="go">    text/plain</span>
<span class="go">    text/plain</span>
<span class="go">    multipart/digest</span>
<span class="go">        message/rfc822</span>
<span class="go">            text/plain</span>
<span class="go">        message/rfc822</span>
<span class="go">            text/plain</span>
<span class="go">        message/rfc822</span>
<span class="go">            text/plain</span>
<span class="go">        message/rfc822</span>
<span class="go">            text/plain</span>
<span class="go">        message/rfc822</span>
<span class="go">            text/plain</span>
<span class="go">    text/plain</span>
</pre></div>
</div>
<p>可选项 <em>fp</em> 是一个作为打印输出目标的文件类对象。 它必须适用于 Python 的 <a class="reference internal" href="functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a> 函数。 <em>level</em> 是供内部使用的。 <em>include_default</em> 如果为真值，则会同时打印默认类型。</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="email.utils.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.utils</span></code>: 其他工具</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="json.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code> --- JSON 编码和解码器</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/email.iterators.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="json.html" title="json --- JSON 编码和解码器"
             >下一页</a> |</li>
        <li class="right" >
          <a href="email.utils.html" title="email.utils: 其他工具"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="netdata.html" >互联网数据处理</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="email.html" ><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code> --- 电子邮件与 MIME 处理包</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>